package com.jumi.microservice.controller.admin;

import com.alibaba.excel.EasyExcel;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.refundgoods.*;
import com.jumi.microservice.service.admin.AdminRefundGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author Scw
 * @Date 2020-08-19 10:10
 */
@Api(tags = {"后台售后管理--退货管理相关接口"})
@RestController
@RequestMapping("/admin/refundGoods")
public class AdminRefundGoodsController extends BaseController {
    @Resource
    private AdminRefundGoodsService adminRefundGoodsService;

    @PostMapping(value = "/refundRemark")
    @ApiOperation("退货备注信息")
    public ResponseResult<Boolean> refundRemark(@RequestBody RefundGoodsRemarkRequest refundGoodsRemarkRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsRemarkRequest.setOperatorId(getUid());
        refundGoodsRemarkRequest.setOperatorName(getUserName());
        result.setData(adminRefundGoodsService.refundRemark(refundGoodsRemarkRequest));
        return result;
    }

    @PostMapping(value = "/addRefundGoods")
    @ApiOperation("退货添加")
    public ResponseResult<Boolean> addRefundGoods(RefundGoodsAddRequest refundGoodsAddRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsAddRequest.setOperatorId(getUid());
        refundGoodsAddRequest.setOperatorName(getUserName());
        result.setData(adminRefundGoodsService.addRefundGoods(refundGoodsAddRequest));
        return result;
    }

    @PostMapping(value = "/addRefundGoodsLogistics")
    @ApiOperation("物流信息添加")
    public ResponseResult<Boolean> addRefundGoodsLogistics(RefundGoodsLogisticsRequest refundGoodsLogisticsRequest, RefundGoodsRequest refundGoodsRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsLogisticsRequest.setOperatorId(getUid());
        refundGoodsLogisticsRequest.setOperatorName(getUserName());
        result.setData(adminRefundGoodsService.addRefundGoodsLogistics(refundGoodsLogisticsRequest, refundGoodsRequest));
        return result;
    }

    @PostMapping(value = "/cancelRefundGoods")
    @ApiOperation("退货取消")
    public ResponseResult<Boolean> cancelRefundGoods(RefundGoodsStatusRequest refundGoodsStatusRequest, RefundGoodsRequest refundGoodsRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsStatusRequest.setOperatorId(getUid());
        refundGoodsStatusRequest.setOperatorName(getUserName());
        result.setData(adminRefundGoodsService.cancelRefundGoods(refundGoodsStatusRequest, refundGoodsRequest));
        return result;
    }

    @PostMapping(value = "/refundGoodsDealWith")
    @ApiOperation("退货处理")
    public ResponseResult<Boolean> refundGoodsDealWith(@RequestBody RefundGoodsDealWithRequest refundGoodsDealWithRequest,RefundGoodsRequest refundGoodsRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsDealWithRequest.setOperatorId(getUid());
        refundGoodsDealWithRequest.setOperatorName(getUserName());
        result.setData(adminRefundGoodsService.refundGoodsDealWith(refundGoodsDealWithRequest, refundGoodsRequest));
        return result;
    }

    @PostMapping(value = "/refundGoodsReceived")
    @ApiOperation("确认收货")
    public ResponseResult<Boolean> refundGoodsReceived(@RequestBody RefundGoodsReceivedRequest refundGoodsReceivedRequest, RefundGoodsRequest refundGoodsRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsReceivedRequest.setOperatorId(getUid());
        refundGoodsReceivedRequest.setOperatorName(getUserName());
        result.setData(adminRefundGoodsService.refundGoodsReceived(refundGoodsReceivedRequest, refundGoodsRequest));
        return result;
    }

    @GetMapping("/refundGoodsStatus/dictionary")
    @ApiOperation("退货状态对照字典")
    public ResponseResult<Map<Integer, String>> getRefundGoodsStatus() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminRefundGoodsService.getRefundGoodsStatus());
        return result;
    }

    @GetMapping("/receivedStatus/dictionary")
    @ApiOperation("收货状态对照字典")
    public ResponseResult<Map<Integer, String>> getReceivedStatus() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminRefundGoodsService.getReceivedStatus());
        return result;
    }

    @GetMapping("/afterSaleReason/dictionary")
    @ApiOperation("售后原因对照字典")
    public ResponseResult<Map<Integer, String>> getAfterSaleReason() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminRefundGoodsService.getAfterSaleReason());
        return result;
    }

    @GetMapping("/refundReason/dictionary")
    @ApiOperation("退货原因对照字典")
    public ResponseResult<Map<Integer, String>> getRefundReason() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminRefundGoodsService.getRefundReason());
        return result;
    }

    @GetMapping(value = "/refundGoodsDealWithView")
    @ApiOperation("退货处理预览信息")
    public ResponseResult<RefundGoodsDealWithViewResponse> refundGoodsDealWithView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsDealWithViewResponse> result = new ResponseResult<>();
        RefundGoodsDealWithViewResponse refundGoodsDealWithViewResponse = adminRefundGoodsService.refundGoodsDealWithView(request);
        result.setData(refundGoodsDealWithViewResponse);
        return result;
    }

    @GetMapping(value = "/refundGoodsReceivedView")
    @ApiOperation("收货预览信息")
    public ResponseResult<RefundGoodsReceivedViewResponse> refundGoodsReceivedView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsReceivedViewResponse> result = new ResponseResult<>();
        RefundGoodsReceivedViewResponse refundGoodsReceivedViewResponse = adminRefundGoodsService.refundGoodsReceivedView(request);
        result.setData(refundGoodsReceivedViewResponse);
        return result;
    }

    @GetMapping(value = "/refundGoodsLogisticsView")
    @ApiOperation("上传单号预览信息")
    public ResponseResult<RefundGoodsLogisticsViewResponse> refundGoodsLogisticsView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsLogisticsViewResponse> result = new ResponseResult<>();
        RefundGoodsLogisticsViewResponse refundGoodsLogisticsViewResponse = adminRefundGoodsService.refundGoodsLogisticsView(request);
        result.setData(refundGoodsLogisticsViewResponse);
        return result;
    }

    @GetMapping(value = "/refundGoodsCheckView")
    @ApiOperation("审核预览信息")
    public ResponseResult<RefundGoodsCheckViewResponse> refundGoodsCheckView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsCheckViewResponse> result = new ResponseResult<>();
        RefundGoodsCheckViewResponse refundGoodsCheckViewResponse = adminRefundGoodsService.refundGoodsCheckView(request);
        result.setData(refundGoodsCheckViewResponse);
        return result;
    }

    @GetMapping(value = "/refundGoodsCompleteView")
    @ApiOperation("完成预览信息")
    public ResponseResult<RefundGoodsCompleteViewResponse> refundGoodsCompleteView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsCompleteViewResponse> result = new ResponseResult<>();
        RefundGoodsCompleteViewResponse refundGoodsCompleteViewResponse = adminRefundGoodsService.refundGoodsCompleteView(request);
        result.setData(refundGoodsCompleteViewResponse);
        return result;
    }

    @GetMapping(value = "/refundGoodsRefuseView")
    @ApiOperation("拒绝预览信息")
    public ResponseResult<RefundGoodsRefuseViewResponse> refundGoodsRefuseView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsRefuseViewResponse> result = new ResponseResult<>();
        RefundGoodsRefuseViewResponse refundGoodsRefuseViewResponse = adminRefundGoodsService.refundGoodsRefuseView(request);
        result.setData(refundGoodsRefuseViewResponse);
        return result;
    }

    @GetMapping(value = "/refundGoodsCancelView")
    @ApiOperation("取消预览信息")
    public ResponseResult<RefundGoodsCancelViewResponse> refundGoodsCancelView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsCancelViewResponse> result = new ResponseResult<>();
        RefundGoodsCancelViewResponse refundGoodsCancelViewResponse = adminRefundGoodsService.refundGoodsCancelView(request);
        result.setData(refundGoodsCancelViewResponse);
        return result;
    }

    @GetMapping(value = "/refundGoodsListView")
    @ApiOperation("全部预览信息")
    public ResponseResult<RefundGoodsListViewResponse> refundGoodsListView(RefundGoodsRequest request) {
        ResponseResult<RefundGoodsListViewResponse> result = new ResponseResult<>();
        RefundGoodsListViewResponse refundGoodsListViewResponse = adminRefundGoodsService.refundGoodsListView(request);
        result.setData(refundGoodsListViewResponse);
        return result;
    }

    @GetMapping("/refundGoodsList")
    @ApiOperation("全部列表")
    TableDataInfo<RefundGoodsListResponse> refundGoodsList(RefundGoodsListRequest request) {
        return adminRefundGoodsService.refundGoodsList(request);
    }

    @GetMapping("/refundGoodsDealWithList")
    @ApiOperation("待处理列表")
    TableDataInfo<RefundGoodsDealWithListResponse> refundGoodsDealWithList(RefundGoodsListRequest request) {
        return adminRefundGoodsService.refundGoodsDealWithList(request);
    }

    @GetMapping("/refundGoodsReceivedList")
    @ApiOperation("待收货列表")
    TableDataInfo<RefundGoodsReceivedListResponse> refundGoodsReceivedList(RefundGoodsReceivedListRequest request) {
        return adminRefundGoodsService.refundGoodsReceivedList(request);
    }

    @GetMapping("/refundGoodsCheckList")
    @ApiOperation("待审核列表")
    TableDataInfo<RefundGoodsCheckListResponse> refundGoodsCheckList(RefundGoodsStepListRequest request) {
        return adminRefundGoodsService.refundGoodsCheckList(request);
    }

    @GetMapping("/refundGoodsCompleteList")
    @ApiOperation("已完成列表")
    TableDataInfo<RefundGoodsCompleteListResponse> refundGoodsCompleteList(RefundGoodsStepListRequest request) {
        return adminRefundGoodsService.refundGoodsCompleteList(request);
    }

    @GetMapping("/refundGoodsRefuseList")
    @ApiOperation("已拒绝列表")
    TableDataInfo<RefundGoodsRefuseListResponse> refundGoodsRefuseList(RefundGoodsCancelListRequest request) {
        return adminRefundGoodsService.refundGoodsRefuseList(request);
    }

    @GetMapping("/refundGoodsCancelList")
    @ApiOperation("已取消列表")
    TableDataInfo<RefundGoodsCancelListResponse> refundGoodsCancelList(RefundGoodsCancelListRequest request) {
        return adminRefundGoodsService.refundGoodsCancelList(request);
    }

    @PostMapping("/exportExcel")
    @ApiOperation("全部导出excel")
    public void exportExcel(ExportRefundGoodsListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportRefundGoodsListResponse> exportRefundGoodsListResponseExportExcelCommonResponse = adminRefundGoodsService.exportExcel(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportRefundGoodsListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportRefundGoodsListResponse.class).sheet("sheet1").doWrite(exportRefundGoodsListResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelDealWith")
    @ApiOperation("待处理导出excel")
    public void exportExcelDealWith(ExportRefundGoodsListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportRefundGoodsDealWithListResponse> exportRefundGoodsDealWithListResponseExportExcelCommonResponse = adminRefundGoodsService.exportExcelDealWith(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportRefundGoodsDealWithListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportRefundGoodsDealWithListResponse.class).sheet("sheet1").doWrite(exportRefundGoodsDealWithListResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelReceived")
    @ApiOperation("待收货导出excel")
    public void exportExcelReceived(ExportRefundGoodsReceivedListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportRefundGoodsReceivedListResponse> exportRefundGoodsDealWithListResponseExportExcelCommonResponse = adminRefundGoodsService.exportExcelReceived(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportRefundGoodsDealWithListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportRefundGoodsReceivedListResponse.class).sheet("sheet1").doWrite(exportRefundGoodsDealWithListResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelCheck")
    @ApiOperation("待审核导出excel")
    public void exportExcelCheck(ExportRefundGoodsStepListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportRefundGoodsCheckListResponse> exportRefundGoodsCheckListResponseExportExcelCommonResponse = adminRefundGoodsService.exportExcelCheck(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportRefundGoodsCheckListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportRefundGoodsCheckListResponse.class).sheet("sheet1").doWrite(exportRefundGoodsCheckListResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelComplete")
    @ApiOperation("已完成导出excel")
    public void exportExcelComplete(ExportRefundGoodsStepListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportRefundGoodsCompleteListResponse> exportRefundGoodsCompleteListResponseExportExcelCommonResponse = adminRefundGoodsService.exportExcelComplete(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportRefundGoodsCompleteListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportRefundGoodsCompleteListResponse.class).sheet("sheet1").doWrite(exportRefundGoodsCompleteListResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelRefuse")
    @ApiOperation("已拒绝导出excel")
    public void exportExcelRefuse(ExportRefundGoodsCancelListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportRefundGoodsRefuseListResponse> exportRefundGoodsRefuseListResponseExportExcelCommonResponse = adminRefundGoodsService.exportExcelRefuse(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportRefundGoodsRefuseListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportRefundGoodsRefuseListResponse.class).sheet("sheet1").doWrite(exportRefundGoodsRefuseListResponseExportExcelCommonResponse.getData());
    }

    @PostMapping("/exportExcelCancel")
    @ApiOperation("已取消导出excel")
    public void exportExcelCancel(ExportRefundGoodsCancelListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportRefundGoodsCancelListResponse> exportRefundGoodsCancelListResponseExportExcelCommonResponse = adminRefundGoodsService.exportExcelCancel(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportRefundGoodsCancelListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportRefundGoodsCancelListResponse.class).sheet("sheet1").doWrite(exportRefundGoodsCancelListResponseExportExcelCommonResponse.getData());
    }
}
